package priv.mill.web;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class HelloSevlet implements Servlet {

	public void destroy() {
		System.out.println("destroy");
	}

	public ServletConfig getServletConfig() {
		System.out.println("getServletConfig");
		return null;
	}

	public String getServletInfo() {
		System.out.println("getServletInfo");
		return null;
	}

	public void init(ServletConfig servletConfig) throws ServletException {
		String user = servletConfig.getInitParameter("user");
		Enumeration<?> names = servletConfig.getInitParameterNames();
		while (names.hasMoreElements()) {
			Object object = names.nextElement();
			System.out.println(object);
		}
		ServletContext servletContext = servletConfig.getServletContext();
		String pass = servletContext.getInitParameter("pass");
		System.out.println(pass);
		System.out.println("init");
		
		String realPath = servletContext.getRealPath("/");
		System.out.println(realPath);
		try {
			URL resource = servletContext.getResource("/");
			System.out.println(resource);
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void service(ServletRequest arg0, ServletResponse arg1) throws ServletException, IOException {
		arg1.getWriter().println("<h1>*is patten</h1>");
		System.out.println("service");

	}

	public HelloSevlet() {
		System.out.println("HelloSevlet");
	}

}
